/**
 * Created by JustBamboo on 2017/9/8.
 *
 * 用户服务接口
 */
import {postRequest, getRequest} from '@/common/request'
import {urls} from './url'

const userApi = urls.user

/**
 * 获取用户列表
 * @param param
 * @param page
 * @param pageSize
 * @param success
 * @param complete
 */
function listUser(param, page, pageSize, success, complete) {
  postRequest(userApi.listUser + '?currentpage=' + page + '&pagesize=' + pageSize, {}, param, success, complete)
}

function listAllUser(param, success, complete) {
  postRequest(userApi.listAllUser, {}, param, success, complete)
}

/**
 * 创建新用户
 * @param param
 * @param success
 * @param complete
 */
function addUser(param, success, complete) {
  postRequest(userApi.addUser, {}, param, success, complete)
}

/**
 * 更新用户信息
 * @param id
 * @param param
 * @param success
 * @param complete
 */
function updateUser(id, param, success, complete) {
  postRequest(userApi.updateUser + id, {}, param, success, complete)
}

/**
 * 更新用户信息
 * @param id
 * @param param
 * @param success
 * @param complete
 */
function pUpdateUser(param, success, complete) {
  postRequest(userApi.pUpdateUser, {}, param, success, complete)
}

/**
 * 更新用户密码
 * @param id
 * @param param
 * @param success
 * @param complete
 */
function updatePassword(param, success, complete) {
  postRequest(userApi.updatePassword, {}, param, success, complete)
}

/**
 * 更新用户密码
 * @param id
 * @param param
 * @param success
 * @param complete
 */
function pUpdatePassword(param, success, complete) {
  postRequest(userApi.pUpdatePassword, {}, param, success, complete)
}

/**
 * 获取用户信息
 * @param id
 * @param success
 * @param complete
 */
function getUserById(id, success, complete) {
  getRequest(userApi.getUserById + id, {}, success, complete)
}

/**
 * 删除用户信息
 * @param ids
 * @param success
 * @param complete
 */
function deleteUser(ids, success, complete) {
  postRequest(userApi.removeUser, {}, ids, success, complete)
}

/**
 *
 * @param ids
 * @param success
 * @param complete
 */
function deleteSingleUser(id, success, complete) {
  let ids = []
  ids.push(id)
  deleteUser(ids, success, complete)
}

export default {
  listUser,
  addUser,
  getUserById,
  updateUser,
  updatePassword,
  deleteUser,
  deleteSingleUser,
  pUpdateUser,
  pUpdatePassword,
  listAllUser
}
